package com.checkCode.code;

import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author 大忽悠
 * @create 2023/2/9 21:55
 */
@Component
public class SimpleCheckCodeGenerator implements CheckCodeGenerator{
    private static final String CANDIDATES="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    /**
     * @param codeLength 验证码长度
     * @return 指定长度的随机验证码
     */
    @Override
    public String generate(Integer codeLength) {
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<CANDIDATES.length();i++){
            int number= ThreadLocalRandom.current().nextInt(CANDIDATES.length());
            sb.append(CANDIDATES.charAt(number));
        }
        return sb.toString();
    }
}
